package com.android.gufengmall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.android.gufengmall.R;
import com.android.gufengmall.bean.FolkCraftBean;
import com.android.gufengmall.bean.TalentBean;

import java.util.List;

public class FolkCraftManagerAdapter extends RecyclerView.Adapter<FolkCraftManagerAdapter.ArticleManagerHolder> {

    private Context mContext;
    private List<FolkCraftBean> mTalentBeans;
    private onCheckSelectListener mListener;

    public FolkCraftManagerAdapter(Context context, List<FolkCraftBean> talentBeanList) {
        mContext = context;
        mTalentBeans = talentBeanList;
    }

    @NonNull
    @Override
    public ArticleManagerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ArticleManagerHolder(LayoutInflater.from(mContext).inflate(R.layout.item_article_manager, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ArticleManagerHolder holder, int position) {
        FolkCraftBean talentBean = mTalentBeans.get(position);
        holder.mTvInfo.setText(talentBean.getTitle());
        holder.mCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
            mListener.OnCheckSelect(position, isChecked);
        });
    }

    @Override
    public int getItemCount() {
        return mTalentBeans.size();
    }

    public class ArticleManagerHolder extends RecyclerView.ViewHolder {

        private final CheckBox mCheckBox;
        private final TextView mTvInfo;

        public ArticleManagerHolder(@NonNull View itemView) {
            super(itemView);

            mTvInfo = itemView.findViewById(R.id.tv_info);
            mCheckBox = itemView.findViewById(R.id.chx_select);
        }
    }

    public interface onCheckSelectListener {
        void OnCheckSelect(int position, boolean isCheck);
    }

    public void setOnCheckSelectListener(onCheckSelectListener onCheckSelectListener) {
        mListener = onCheckSelectListener;
    }
}
